package com.txunda.zhuohired.aty.manage.my;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.widget.TextView;

import com.lidroid.xutils.view.annotation.ViewInject;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.base.BaseAty;
import com.txunda.zhuohired.fgt.manage.ManageResumeDateFgt;
import com.txunda.zhuohired.http.pst.UserPst;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/3/14 13:18
 * 功能描述：面试日程
 * 联系方式：jiahuanchen@126.com
 */

public class ManageResumeDateAty extends BaseAty {
    /**
     * 标题
     */
    @ViewInject(R.id.tv_layout_white_center)
    private TextView tv_layout_white_center;
    /**
     * tabLayout
     */
    @ViewInject(R.id.tl_manage_resume_date)
    private TabLayout tl_manage_resume_date;
    /**
     * viewPager
     */
    @ViewInject(R.id.vp_manage_resume_date)
    private ViewPager vp_manage_resume_date;

    private ArrayList<Fragment> mFragments;
    private MyPagerAdapter myPagerAdapter;

    private List<String> tittleList;
    private int curMonth;
    private int curDate;
    private String date = "";
    private String date1 = "";


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        showStatusBar(R.id.layout_white_head);
        tv_layout_white_center.setText("面试日程");
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.aty_manage_resume_date;
    }

    @Override
    protected void initialized() {


        Calendar c = Calendar.getInstance();
        int curYear = c.get(Calendar.YEAR);
        curMonth = c.get(Calendar.MONTH) + 1;//通过Calendar算出的月数要+1
        curDate = c.get(Calendar.DATE);
        //        String month = "";
        //        String day = "";
        //        if (curMonth < 10) {
        //            month = "0" + curMonth;
        //        } else {
        //            month = "" + curMonth;
        //        }
        //        if (curDate < 10) {
        //            day = "0" + curDate;
        //        } else {
        //            day = "" + curDate;
        //        }
        date = curMonth + "月" + curDate + "日";
        date1 = curMonth + "月" + (curDate + 1) + "日";
        tittleList = new ArrayList();
        tittleList.add("今日" + date);
        tittleList.add("明日" + date1);
        mFragments = new ArrayList<>();
        myPagerAdapter = new MyPagerAdapter(getSupportFragmentManager());
        mFragments.add(ManageResumeDateFgt.getFgt(0));
        mFragments.add(ManageResumeDateFgt.getFgt(1));

    }

    @Override
    protected void requestData() {
        initAdapter();
    }

    private void initAdapter(){
        vp_manage_resume_date.setAdapter(myPagerAdapter);
        tl_manage_resume_date.setupWithViewPager(vp_manage_resume_date);
    }

    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }


        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return tittleList.get(position);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }
    }
}
